Skip to content

TEL-886: Media Port rework - #802

Open
alexlivekit wants to merge 2 commits into
mainfrom
tel-886/media-port
Open

TEL-886: Media Port rework#802
alexlivekit wants to merge 2 commits into
mainfrom
tel-886/media-port

Conversation

@alexlivekit

@alexlivekit alexlivekit commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This change is intended to:

  • Have little functional differences between it an main.
    • the one known thing: Plug-in processor moved back to ingesting 48khz audio and returning 48khz audio.
  • Add interface for clarity.
  • Add machinery to support renegotiation, early media, hold, etc. All these are still disabled for now, but there.
  • Add tests.

@alexlivekit
alexlivekit requested a review from a team as a code owner August 20, 2026 19:20
devin-ai-integration[bot]

This comment was marked as resolved.

@alexlivekit

Copy link
Copy Markdown
Contributor Author

Huh, the race in CI is real, and is apparently a problem in media-sdk (yay zerocopy) that previous tests simply did not expose.
So... no regression compared to main.

@alexfish8

Copy link
Copy Markdown
Contributor

Huh, the race in CI is real, and is apparently a problem in media-sdk (yay zerocopy) that previous tests simply did not expose. So... no regression compared to main.

Will fix this in media-sdk.

devin-ai-integration[bot]

This comment was marked as resolved.

@alexlivekit alexlivekit mentioned this pull request Aug 21, 2026
Comment thread pkg/sip/inbound.go Outdated
Comment thread pkg/sip/inbound.go
Comment thread pkg/sip/inbound.go
w := c.lkRoom.SwapOutput(nil)
// Mute the room audio to the SIP participant.
// Skip closing the existing writer, which is c.audioOut.
_ = c.lkRoom.WriteOutboundAudioTo(nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep w as it was before? It makes sure we swap back to the same pipeline that was used before the transfer.

For closing, if I read it correctly, it's already protected by NopCloser in the media pipeline, right? So we should close here to avoid leaks, and media pipeline will decide if it wants to expose close or not.

Comment thread pkg/sip/media_pipeline.go Outdated
Comment thread pkg/sip/media_pipeline.go Outdated
Comment thread pkg/sip/media_pipeline.go Outdated
Comment thread pkg/sip/media_port.go
Comment thread pkg/sip/media_port.go
return errors.New("unexpected local address change")
}

audioToPort := p.audioOut.Swap(nil) // either nil or no-op closer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert that it's the case during swap?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow. Are you talking about something like:

audioToPort := p.audioOut.Swap(nil)
if audioToPort != nil {
  if _, ok := audioToPort.(msdk.writeCloser[x]); !ok {
    log.Errorw(...)
  }
}

?

The only thin that swaps these is the configure function itself, so I'm not sure what the benefit would be there.
The comment is there to explain why we don't close the popped value.

Comment thread pkg/sip/outbound.go
Comment thread pkg/sip/room.go

// WriteOutboundDTMFTo tells the room where to send DTMF to.
// Returns the previously-set writer (if one exists).
WriteOutboundDTMFTo(w msdk.WriteCloser[*livekit.SipDTMF]) msdk.WriteCloser[*livekit.SipDTMF]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason to use pointers in livekit.SipDTMF? It's a tiny payload, might as well just copy it around.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the thread safety is a good benefit of copying. Fair enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteSample passes lock by value: github.com/livekit/protocol/livekit.SipDTMF contains google.golang.org/protobuf/runtime/protoimpl.MessageState contains sync.Mutex I guess this is one,

Base automatically changed from tel-886/prep to main August 21, 2026 16:42
@alexlivekit
alexlivekit force-pushed the tel-886/media-port branch 2 times, most recently from df94a89 to 4ab15fe Compare August 21, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants